﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;

namespace Macds.Core.Remoting
{
    public class BindingFactory
    {
        public static Binding CreateBinding(BindingType type)
        {
            switch(type)
            {
                case BindingType.Tcp:
                    return CreateTcpBinding();
                default:
                    return BindingLocator.CustomBinding;
            }
        }

        public static Binding CreateTcpBinding()
        {
            NetTcpBinding tcpBinding = new NetTcpBinding(SecurityMode.Transport);
            tcpBinding.Security.Mode = SecurityMode.None;
            tcpBinding.SendTimeout = new TimeSpan(0, 2, 0);

            // Binding Message Size
            tcpBinding.MaxReceivedMessageSize = int.MaxValue;
            tcpBinding.MaxBufferPoolSize = int.MaxValue;
            tcpBinding.MaxConnections = 10;
            tcpBinding.MaxBufferSize = int.MaxValue;

            // Reader Message Size
            tcpBinding.ReaderQuotas.MaxArrayLength = int.MaxValue;
            tcpBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            tcpBinding.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
            tcpBinding.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;

            return tcpBinding;
        }
    }
}
